<script setup>
import { watchEffect, onMounted } from "vue";
import { RouterView } from "vue-router";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import enUs from "element-plus/es/locale/lang/en";
import { ElConfigProvider } from "element-plus";
import { useUserStore } from "@/stores/userStore";
import { useI18n } from "vue-i18n";

const user = useUserStore();
const { locale } = useI18n();
watchEffect(() => {
  locale.value = user.user.lang;
});

onMounted(() => {
  const theme = window.localStorage.getItem("theme");
  document.documentElement.setAttribute("data-theme", theme || "standard");
});
</script>

<template>
  <el-config-provider :locale="user.user.lang === '' ? zhCn : enUs">
    <router-view v-slot="{ Component }">
      <keep-alive>
        <component :is="Component" />
      </keep-alive>
    </router-view>
  </el-config-provider>
</template>

<style scoped lang="scss"></style>
